/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import entities.Event;
import entities.User;
import java.util.ArrayList;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Alberto, Alessandra
 */
@Stateless
public class UserLoader {
    
    @PersistenceContext
    EntityManager em;
    
    public User loadProfile (String username) {
        return em.createNamedQuery("findByUsername" , User.class)
                .setParameter("Uusername", username)
                .getSingleResult();
    }
    
    public ArrayList<Event> loadCalendar (User user) {
        ArrayList<Event> events = new ArrayList<>();
        events.addAll(user.getEvents());
        return events;
    }
    
}
